package com.xxlie.core.model;

import com.xxlie.core.common.ExceptionEnums;

import java.io.Serializable;
import java.util.Date;

/**
 * .model
 *
 * @author xxlie.com
 * @since 2017/7/30
 */
public class View<T> implements Serializable {

    private Date timestamp;
    private int code;
    private String message;
    private T data;

    public View() {
    }

    public View(final int code, final String message) {
        this.code = code;
        this.message = message;
        this.timestamp = new Date();
    }

    public static <T> View<T> of(final int code, final String message) {
        return new View<>(code, message);
    }

    public static <T> View<T> of(final ExceptionEnums exceptionEnums) {
        return new View<>(exceptionEnums.getCode(), exceptionEnums.getMessage());
    }

    public static <T> View<T> ofError(final String message) {
        return new View<>(50000, message);
    }

    public static <T> View<T> ofOk() {
        return new View<>(20000, "OK");
    }

    public static <T> View<T> ofOk(final String message) {
        return new View<>(20000, message);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Date getTimestamp() {
        return timestamp;
    }
}
